#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,cnt=0,max=0;
	cin>>n;
	vector<int> v1(n+1),v2(n+1),ans;
	for(int i=1;i<n+1;i++){
		cin>>v1[i];
		v2[i]=v1[i];
	}
	sort(v1.begin()+1,v1.end());
	for(int i=1;i<n+1;i++){
		if(v2[i]==v1[i]&&v2[i]>max){
			ans.push_back(v2[i]);
			cnt++;
		}
		if(v2[i]>max) max=v2[i];
	}
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++){
		if(i!=0) printf(" ");
		printf("%d",ans[i]);
	}	
	return 0;
} 
